home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Best of MacTutor - S…e Code for Volumes 1 to 5
/
The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin
/
Source Code
/
#26 (Nov 87)
/
Forth Multifinder
/
V3#11 source
Wrap
Text File
|
1987-09-04
|
6KB
|
264 lines
\ © 1987 J.Langowski / MacTutor
\ with parts of the code © Palo Alto Shipping
\ add this code to the IOTASK code supplied by
\ Palo Alto Shipping, and modify main event loop as indicated
.TRAP _WaitNextEvent $A860
CODE WaitNextEvent
( eventMask VAR-eventRecord sleep mouseRgn -- flag )
EXG D4,A7
CLR.W -(A7) \ function result
MOVE.W $E(A6),-(A7) \ eventMask
MOVE.L $8(A6),-(A7) \ eventRecord
MOVE.L $4(A6),-(A7) \ sleep
MOVE.L (A6),-(A7) \ mouseRgn
ADDA.W #$10,A6
_WaitNextEvent
MOVE.W (A7)+,D0 \ flag -> D0
EXT.L D0 \ extend sign
MOVE.L D0,-(A6) \ push on Forth stack
EXG D4,A7
RTS
END-CODE
Header JugglerThere -1 , \ initially -1 so that first call
\ to GetNextEvent will determine state
\ ========= The Main Loop ===========
: DialogEvent? ( - f )
\ If the event is a dialog event which should be handled
\ by our application
\ (usually be being passed to DialogSelect),
\ IsDialogEvent will return a true flag. If the event
\ should be handled as a normal, non-dialog event, false
\ will be returned.
EVENT-RECORD CALL IsDialogEvent ;
: GetNextEvent ( - f )
\ If an event occurs which should be handled,
\ GetNextEvent will return a true flag.
\ The event code and any other event information
\ will be returned in the EVENT-RECORD.
\ changed for Juggler support 26.8.87 JL
['] JugglerThere @ CASE
1 OF \ Yes, we can juggle
EveryEvent Event-Record 1 0 WaitNextEvent
ENDOF
0 OF \ no, we can't
CALL SystemTask
\ built in here since WaitNextEvent doesn't need it
EveryEvent Event-Record CALL GetNextEvent
ENDOF
-1 OF WNETrap# CALL GetTrapAddress
UnkTrap# CALL GetTrapAddress
= IF CALL SystemTask 0
ELSE 1 THEN
['] JugglerThere !
EveryEvent EVENT-RECORD CALL GetNextEvent
ENDOF
0 \ we should never get here
ENDCASE
;
\ ===== (IOTASK) =====
: (IOTask) { | dialogflag eventflag -- }
BEGIN
BEGIN
GetNextEvent -> eventflag
DialogEvent? -> dialogflag
dialogflag IF
HandleDialog
ELSE
eventflag IF HandleEvent THEN
THEN
eventflag 0=
UNTIL
PAUSE
AGAIN ;
\ Reflections
\ Mach2.12 Demo
\ 6/87
\ Palo Alto Shipping Company
\ Description:
\ (xx1,yy1) and (xx2,yy2) are two points that travel around the
\ reflections window. Their speeds are the delta values held in the
\ DOT variables. When a point runs into a wall, it's x or y speed is
\ negated so that it bounces off the wall. All the while a line is
\ drawn between the two points and the line drawn 20 steps ago is \ erased.
ONLY FORTH DEFINITIONS ALSO MAC
DECIMAL
\ QuickDraw Equates
$8 CONSTANT PatCopy
$B CONSTANT PatBic
$10 CONSTANT PortRect
\ Window Size Variables
VARIABLE WTop
VARIABLE WLeft
VARIABLE WBottom
VARIABLE WRight
VARIABLE WWidth
VARIABLE WHeight
\ Positions \ Velocities
VARIABLE xx1 VARIABLE xx1DOT
VARIABLE yy1 VARIABLE yy1DOT
VARIABLE xx2 VARIABLE xx2DOT
VARIABLE yy2 VARIABLE yy2DOT
\ Menu constants and variables.
VARIABLE DeskName 252 VALLOT
$44525652 CONSTANT 'DRVR'
CREATE AppleString \ Creating title string for AppleMenu.
$01 C, \ Length byte.
$14 C, \ Apple character.
\ Creating a window named 'Reflections'.
NEW.WINDOW Reflections " Reflections" Reflections TITLE
#115 #315 #265 #465 Reflections BOUNDS
ROUNDED VISIBLE NOCLOSEBOX NOGROWBOX
Reflections ITEMS
\ 'LinesTask' is a task w/ 800 bytes of parameter stack.
#800 #1000 TERMINAL LinesTask
\ Give 'Reflections' a menubar.
NEW.MBAR ReflectMBar
NEW.MENU AppleMenu
AppleString AppleMenu TITLE
0 #998 AppleMenu BOUNDS
" (Reflections;(-" AppleMenu ITEMS
NEW.MENU FileMenu
" File" FileMenu TITLE
0 #999 FileMenu BOUNDS
" Quit/Q" FileMenu ITEMS
: HandleDeskAcc { item# | saveport -- }
^ saveport CALL GetPort
AppleMenu @ item# DeskName CALL GetItem
DeskName CALL OpenDeskAcc DROP
saveport CALL SetPort ;
: DoApple ( item# - ) HandleDeskAcc ;
: DoFile ( item# - ) DROP BYE ;
: MbarHandler ( item# menuID - )
CASE
#998 OF DoApple ENDOF
#999 OF DoFile ENDOF
ENDCASE
0 CALL HiliteMenu ;
: RANGE { value hi lo - value flag }
value hi value > lo value < OR NOT ;
: 4DUP ( n1 n2 n3 n4 - n1 n2 n3 n4 n1 n2 n3 n4 )
#3 pick #3 pick #3 pick #3 pick ;
: GetWCoords { wptr | wrect -- }
wptr PortRect + -> wrect
wrect W@ L_EXT WTop !
wrect 2+ W@ L_EXT WLeft !
wrect 4 + W@ L_EXT WBottom !
wrect 6 + W@ L_EXT WRight !
WBottom @ WTop @ - WHeight !
WRight @ WLeft @ - WWidth ! ;
: Exit? ( - f )
?TERMINAL IF
KEY IF BYE THEN
THEN ;
: SetupReflect ( - )
Reflections CALL SetPort
CLS
WWidth @ 3 / xx1 ! #3 xx1DOT !
WHeight @ yy1 ! #-4 yy1DOT !
WWidth @ 3 / 2* xx2 ! #4 xx2DOT !
WHeight @ yy2 ! #-3 yy2DOT ! ;
\ Draws a newline and leaves coords on stack.
: NewCoords ( - xx1 yy1 xx2 yy2 )
xx1Dot @ xx1 +! yy1Dot @ yy1 +!
xx2Dot @ xx2 +! yy2Dot @ yy2 +!
xx1 @ 1 WWidth @ RANGE NOT
IF xx1Dot @ NEGATE xx1Dot !
THEN
yy1 @ 1 WHeight @ RANGE NOT
IF yy1Dot @ NEGATE yy1Dot !
THEN
xx2 @ 1 WWidth @ RANGE NOT
IF xx2Dot @ NEGATE xx2Dot !
THEN
yy2 @ 1 WHeight @ RANGE NOT
IF yy2Dot @ NEGATE yy2Dot !
THEN ;
\ Leaves 40 coordinate pairs on the stack and draws the
\ 1st 20 lines.
: First20Lines ( - )
#20 0 DO
Reflections CALL SetPort
PatCopy CALL PenMode
NewCoords 4DUP
CALL MoveTo CALL LineTo
LOOP ;
: LinesForever ( - )
BEGIN
Reflections CALL SetPort
PatCopy CALL PenMode
NewCoords 4DUP
CALL MoveTo
CALL LineTo ( 21 complete sets on => 84 values)
#83 ROLL #83 ROLL #83 ROLL #83 ROLL
PatBic CALL PenMode ( and white out the n-21st line)
CALL MoveTo CALL LineTo
exit? AGAIN ;
: Reflect ( - ) SetUpReflect First20Lines LinesForever ;
: InitMBar ( - )
ReflectMBar ADD
ReflectMBar AppleMenu ADD
ReflectMBar FileMenu ADD
AppleMenu @ 'DRVR' CALL ADDRESMENU
ReflectMBar @ CALL SetMenuBar
CALL DrawMenuBar ;
: InitStructures ( - )
Reflections ADD
Reflections CALL SelectWindow
Reflections GetWCoords
Reflections LinesTask BUILD
InitMBar ;
: Run ( taskptr - )
ACTIVATE
['] MbarHandler MENU-VECTOR !
ReflectMBar LinesTask MBAR>TASK
Reflect ;
: BootLines ( - ) InitStructures LinesTask Run ;